package com.graduation.springbootinit.controller;

import com.graduation.springbootinit.common.BaseResponse;
import com.graduation.springbootinit.common.ResultUtils;
import com.graduation.springbootinit.model.entity.ShopPart.ProductImage;
import com.graduation.springbootinit.model.request.ProductImageBatchRequest;
import com.graduation.springbootinit.service.ProductImageService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/product/image")
public class ProductImageController {

    @Resource
    private ProductImageService productImageService;

    @PostMapping("/save")
    public BaseResponse<Boolean> saveProductImages(@RequestBody ProductImageBatchRequest request) {
        productImageService.saveProductImages(request.getProductId(), request.getImageNames());
        return ResultUtils.success(true);
    }

    @PostMapping("/delete")
    public BaseResponse<Boolean> deleteProductImage(@RequestBody ProductImage productImage) {
        productImageService.deleteProductImage(productImage.getId());
        return ResultUtils.success(true);
    }

    @PostMapping("/delete/product")
    public BaseResponse<Boolean> deleteByProductId(@RequestBody ProductImage productImage) {
        productImageService.deleteByProductId(productImage.getProductId());
        return ResultUtils.success(true);
    }

    @PostMapping("/list")
    public BaseResponse<List<ProductImage>> getProductImages(@RequestBody ProductImage productImage) {
        List<ProductImage> images = productImageService.getImagesByProductId(productImage.getProductId());
        return ResultUtils.success(images);
    }
} 